<?php

/**
 * 主控制器
 *
 * A basic controller example.  Has examples of how to set the
 * \Response body and status.
 *
 * @package  app
 * @extends  Controller
 */
class Controller_Test  extends Controller_Template {

    public function before(){
        parent::before();
    }

    /**
     * 默认方法
     *
     * @access  public
     * @return  \Response
     */
    public function action_index()
    {
        return \Response::forge(\View::forge('testcase/index'));
    }

    /**
     * 默认方法
     *
     * @access  public
     * @return  \Response
     */
    public function action_alipay() {

        $params = array();
        if(\Input::method() == 'POST'){
            $data = \Input::post();
            $data['order_name'] = '测试订单';
            $data['order_body'] = '测试订单内容';
            $data['order_no'] = 'E' . $data['from_id'] . $data['user_id'] . time();

            $seller = \Model_Seller::find($data['from_id']);

            $order = \Model_Order::forge($data);
            if(! $order->save()){
                die('订单创建失败');
            }
            \Response::redirect("/services/gateway/pay/alipay?order_id={$order->id}");
            return \Response::forge(\View::forge('pay/alipay', $params));
        }

        return \Response::forge(\View::forge('testcase/pay_case'));
    }
}